﻿using cpe.cpein.SERVER.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace cpe.cpein.SERVER.Tools
{
    public static partial class ObjectConverter
    {
        /// <summary>
        /// Function used to convert a WS Address to a Data Address.
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static DATA.Address AddressConverter(Address Address)
        {
            if (Address == null)
                return null;

            return new DATA.Address()
            {
                add_id = Address.Id,
                add_address = Address.Addr,
                add_city = Address.City,
                add_gpsx = Address.GpsX,
                add_gpsy = Address.GpsY,
                add_zipcode = Address.Zipcode,
                cou_id = Address.IDCountry, 
                add_label = Address.Label,
                add_isdeleted = Address.IsDeleted,
            };
        }

        /// <summary>
        /// Function used to convert a Data Address to a WS Address.
        /// </summary>
        /// <param name="?"></param>
        /// <returns></returns>
        public static Address AddressConverter(DATA.Address Address)
        {
            if (Address == null)
                return null;

            Country country = Tools.ObjectConverter.CountryConverter(BUSINESS.BUCountry.GetCountryByID(Address.Country.cou_id));


            return new Address()
            {
                Id = Address.add_id,
                Addr = Address.add_address,
                City = Address.add_city,
                GpsX = Address.add_gpsx,
                GpsY = Address.add_gpsy,
                Zipcode = Address.add_zipcode,
                IDCountry = Address.Country.cou_id,
                Country = country,
                Label = Address.add_label,
                IsDeleted = Address.add_isdeleted,
            };
        }

        /// <summary>
        /// Function used to convert a list of Data Addresss to a List of WS Addresss.
        /// </summary>
        /// <param name="Addresss"></param>
        /// <returns></returns>
        public static List<Address> AddressConverter(List<DATA.Address> Addresss)
        {
            List<Address> res = new List<Address>();
            foreach (DATA.Address us in Addresss)
                res.Add(Tools.ObjectConverter.AddressConverter(us));

            return res;
        }

        /// <summary>
        /// Function used to convert a list of WS Addresss to a List of Data Addresss.
        /// </summary>
        /// <param name="Addresss"></param>
        /// <returns></returns>
        public static List<DATA.Address> AddressConverter(List<Address> Addresss)
        {
            List<DATA.Address> res = new List<DATA.Address>();
            foreach (Address us in Addresss)
                res.Add(Tools.ObjectConverter.AddressConverter(us));

            return res;
        }
    }
}